package com.apes.framework.plugin.soe.metadata;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 功能：场景实例
 *
 * @author xul
 * @create 2018-09-21 11:37
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SceneInstance.CONST_TABLE_NAME)
public class SceneInstance extends BaseModel {
    public static final String CONST_TABLE_NAME = "soe_scene_inst";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "场景实例")
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scene_id", referencedColumnName = "id", nullable = false)
    @Comment("场景")
    private Scene scene;

    @Column(name = "suspend", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否挂起")
    private boolean suspend = false;

    @Column(name = "finished", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否结束")
    private boolean finished = false;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sceneInstance")
    private Set<SceneInstanceRole> sceneInstanceRoles = new HashSet(); //场景实例角色

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sceneInstance")
    private Set<SceneInstanceFlow> sceneInstanceFlows; //场景流
}
